CONTENTS | INDEX | PREV | NEXT
chdir
NAME
chdir - change current directory
SYNOPSIS
int r = chdir(path);
const char *path;
UNIX call
FUNCTION
Changes the current directory to the specified path returning 0 on
success and -1 on failure.
NOTE
when a program exits, the original directory will be restored.
EXAMPLE
#include <stdio.h>
char buf[512];
main(ac, av)
int ac;
char *av[];
{
getcwd(buf, sizeof(buf));
if (chdir("RAM:")) {
puts("Couldn't chdir into RAM:");
exit(1);
}
{
FILE *fp;
if (fp = fopen("yy", "w")) {
fclose(fp);
puts("created file yy in RAM:");
}
}
if (chdir(buf)) {
printf("Unable to chdir back into %sn", buf);
}
return(0);
}
INPUTS
char *path; path to chdir into
RESULTS
int r; return value, 0 if ok, -1 if error
SEE ALSO
getcwd